home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / AppleScript / Development Tools / Tools Goodies / AEGizmos 1.4.1 / Headers / AESubDescs_CPlus.h < prev    next >
Encoding:
Text File  |  1995-01-24  |  2.8 KB  |  85 lines  |  [TEXT/MMCC]

  1. // AESubDescs_CPlus.h
  2. //
  3. // A high-efficiency way to examine AEDescs. Everything is done in place, without any
  4. // copying of data, which avoids most of the overhead of the Apple Event Manager.
  5. //
  6. // By Jens Alfke; Copyright ©1992 Apple Computer. All Rights Reserved.
  7.  
  8.  
  9. #ifdef THINK_C
  10. #pragma once                                        /* For THINK C users */
  11. #endif
  12.  
  13. #ifndef __AESUBDESCS__
  14. #define __AESUBDESCS__                                /* For poor MPW users :) */
  15.  
  16. #include <AppleEvents.h>
  17.  
  18. enum{                                                // Error code
  19.     errAEListIsFactored        = -1760                        // I cannot get data from factored lists
  20. };
  21.  
  22.  
  23. struct AESubDesc;
  24.  
  25.  
  26. extern "C" {
  27.     pascal void
  28.         AEDescToSubDesc( const AEDesc*, AESubDesc* );                    // Create subDesc on desc
  29.     pascal OSErr
  30.         AESubDescToDesc( const AESubDesc*, long desiredType, AEDesc* );    // Copy subDesc to new desc
  31.     
  32.     pascal DescType
  33.         AEGetSubDescType( const AESubDesc* );                            // Same as ->subDescType
  34.     pascal void*
  35.         AEGetSubDescData( const AESubDesc*, long *length );                // Invalid once dataHandle moves
  36.     
  37.     pascal Boolean
  38.         AESubDescIsListOrRecord( const AESubDesc* );    // Is it a list or (possibly coerced) record?
  39.     pascal DescType
  40.         AEGetSubDescBasicType( const AESubDesc* );        // Returns 'reco' if it's a coerced record
  41.     
  42.     // The list-oriented calls that follow make sure the subdescriptor is a valid list or (possibly
  43.     // coerced) record. If not, they'll return errAEWrongDataType.
  44.     
  45.     pascal long
  46.         AECountSubDescItems( const AESubDesc* );
  47.     
  48.     // In these next two calls, it's okay if newSD == sd; sd will be overwritten with the new subDesc.
  49.         
  50.     pascal OSErr
  51.         AEGetNthSubDesc( const AESubDesc* sd, long index,
  52.                          AEKeyword* keyIfAny = NULL, AESubDesc* newSD ),
  53.         AEGetKeySubDesc( const AESubDesc* sd, AEKeyword,                // Lists illegal here
  54.                          AESubDesc* newSD );
  55. };
  56.  
  57.  
  58. struct AESubDesc {
  59.     public:
  60.     
  61.     AESubDesc( const AEDesc &desc )                {AEDescToSubDesc(desc,this);}
  62.     
  63.     DescType    GetType( void ) const            {return subDescType;}
  64.     DescType    GetBasicType( void ) const        {return AEGetSubDescType(this);}
  65.     Boolean        IsListOrRecord( void ) const    {return AESubDescIsListOrRecord(this);}
  66.     
  67.     const void*    GetData( long *length =NULL ) const
  68.                                                 {return AEGetSubDescData(length);}
  69.     long        GetDataLength( void ) const        {long length; AEGetSubDescData(&length); return length;}
  70.     
  71.     long        CountItems( void ) const        {return AECountSubDescItems(this);}
  72.     
  73.     OSErr        GetNth( long index, AESubDesc *newSD, AEKeyword *keyIfAny =NULL ) const
  74.                                                 {return AEGetNthSubDesc(this,index,keyIfAny,newSD);}
  75.     OSErr        GetKey( AEKeyword key, AESubDesc *newSD ) const
  76.                                                 {return AEGetKeySubDesc(this,key,newSD);}
  77.  
  78.     private:
  79.     DescType    subDescType;        // Type of this subDesc. You may read this field.
  80.     Handle        dataHandle;            // Handle to main (outer) descriptor. Private.
  81.     long        offset;                // Offset into main descriptor where subDesc starts. Private.
  82. };
  83.  
  84.  
  85. #endif